/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class OfferListing
    {
    
        private String offerListingIdField;

        private String exchangeIdField;

        private  Price priceField;
        private  Price salePriceField;
        private  Price amountSavedField;
        private Decimal? percentageSavedField;

        private String availabilityField;

        private  AvailabilityAttributes availabilityAttributesField;
        private Decimal? quantityField;

        private  Address ISPUStoreAddressField;
        private String ISPUStoreHoursField;

        private Boolean? isEligibleForSuperSaverShippingField;

        private String salesRestrictionField;

        private  List<ShippingCharge> shippingChargeField;


        /// <summary>
        /// Gets and sets the OfferListingId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "OfferListingId")]
        public String OfferListingId
        {
            get { return this.offerListingIdField ; }
            set { this.offerListingIdField= value; }
        }



        /// <summary>
        /// Sets the OfferListingId property
        /// </summary>
        /// <param name="offerListingId">OfferListingId property</param>
        /// <returns>this instance</returns>
        public OfferListing WithOfferListingId(String offerListingId)
        {
            this.offerListingIdField = offerListingId;
            return this;
        }



        /// <summary>
        /// Checks if OfferListingId property is set
        /// </summary>
        /// <returns>true if OfferListingId property is set</returns>
        public Boolean IsSetOfferListingId()
        {
            return  this.offerListingIdField != null;

        }


        /// <summary>
        /// Gets and sets the ExchangeId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ExchangeId")]
        public String ExchangeId
        {
            get { return this.exchangeIdField ; }
            set { this.exchangeIdField= value; }
        }



        /// <summary>
        /// Sets the ExchangeId property
        /// </summary>
        /// <param name="exchangeId">ExchangeId property</param>
        /// <returns>this instance</returns>
        public OfferListing WithExchangeId(String exchangeId)
        {
            this.exchangeIdField = exchangeId;
            return this;
        }



        /// <summary>
        /// Checks if ExchangeId property is set
        /// </summary>
        /// <returns>true if ExchangeId property is set</returns>
        public Boolean IsSetExchangeId()
        {
            return  this.exchangeIdField != null;

        }


        /// <summary>
        /// Gets and sets the Price property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Price")]
        public Price Price
        {
            get { return this.priceField ; }
            set { this.priceField = value; }
        }



        /// <summary>
        /// Sets the Price property
        /// </summary>
        /// <param name="price">Price property</param>
        /// <returns>this instance</returns>
        public OfferListing WithPrice(Price price)
        {
            this.priceField = price;
            return this;
        }



        /// <summary>
        /// Checks if Price property is set
        /// </summary>
        /// <returns>true if Price property is set</returns>
        public Boolean IsSetPrice()
        {
            return this.priceField != null;
        }




        /// <summary>
        /// Gets and sets the SalePrice property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SalePrice")]
        public Price SalePrice
        {
            get { return this.salePriceField ; }
            set { this.salePriceField = value; }
        }



        /// <summary>
        /// Sets the SalePrice property
        /// </summary>
        /// <param name="salePrice">SalePrice property</param>
        /// <returns>this instance</returns>
        public OfferListing WithSalePrice(Price salePrice)
        {
            this.salePriceField = salePrice;
            return this;
        }



        /// <summary>
        /// Checks if SalePrice property is set
        /// </summary>
        /// <returns>true if SalePrice property is set</returns>
        public Boolean IsSetSalePrice()
        {
            return this.salePriceField != null;
        }




        /// <summary>
        /// Gets and sets the AmountSaved property.
        /// </summary>
        [XmlElementAttribute(ElementName = "AmountSaved")]
        public Price AmountSaved
        {
            get { return this.amountSavedField ; }
            set { this.amountSavedField = value; }
        }



        /// <summary>
        /// Sets the AmountSaved property
        /// </summary>
        /// <param name="amountSaved">AmountSaved property</param>
        /// <returns>this instance</returns>
        public OfferListing WithAmountSaved(Price amountSaved)
        {
            this.amountSavedField = amountSaved;
            return this;
        }



        /// <summary>
        /// Checks if AmountSaved property is set
        /// </summary>
        /// <returns>true if AmountSaved property is set</returns>
        public Boolean IsSetAmountSaved()
        {
            return this.amountSavedField != null;
        }




        /// <summary>
        /// Gets and sets the PercentageSaved property.
        /// </summary>
        [XmlElementAttribute(ElementName = "PercentageSaved")]
        public Decimal PercentageSaved
        {
            get { return this.percentageSavedField.GetValueOrDefault() ; }
            set { this.percentageSavedField= value; }
        }



        /// <summary>
        /// Sets the PercentageSaved property
        /// </summary>
        /// <param name="percentageSaved">PercentageSaved property</param>
        /// <returns>this instance</returns>
        public OfferListing WithPercentageSaved(Decimal percentageSaved)
        {
            this.percentageSavedField = percentageSaved;
            return this;
        }



        /// <summary>
        /// Checks if PercentageSaved property is set
        /// </summary>
        /// <returns>true if PercentageSaved property is set</returns>
        public Boolean IsSetPercentageSaved()
        {
            return  this.percentageSavedField != null;

        }


        /// <summary>
        /// Gets and sets the Availability property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Availability")]
        public String Availability
        {
            get { return this.availabilityField ; }
            set { this.availabilityField= value; }
        }



        /// <summary>
        /// Sets the Availability property
        /// </summary>
        /// <param name="availability">Availability property</param>
        /// <returns>this instance</returns>
        public OfferListing WithAvailability(String availability)
        {
            this.availabilityField = availability;
            return this;
        }



        /// <summary>
        /// Checks if Availability property is set
        /// </summary>
        /// <returns>true if Availability property is set</returns>
        public Boolean IsSetAvailability()
        {
            return  this.availabilityField != null;

        }


        /// <summary>
        /// Gets and sets the AvailabilityAttributes property.
        /// </summary>
        [XmlElementAttribute(ElementName = "AvailabilityAttributes")]
        public AvailabilityAttributes AvailabilityAttributes
        {
            get { return this.availabilityAttributesField ; }
            set { this.availabilityAttributesField = value; }
        }



        /// <summary>
        /// Sets the AvailabilityAttributes property
        /// </summary>
        /// <param name="availabilityAttributes">AvailabilityAttributes property</param>
        /// <returns>this instance</returns>
        public OfferListing WithAvailabilityAttributes(AvailabilityAttributes availabilityAttributes)
        {
            this.availabilityAttributesField = availabilityAttributes;
            return this;
        }



        /// <summary>
        /// Checks if AvailabilityAttributes property is set
        /// </summary>
        /// <returns>true if AvailabilityAttributes property is set</returns>
        public Boolean IsSetAvailabilityAttributes()
        {
            return this.availabilityAttributesField != null;
        }




        /// <summary>
        /// Gets and sets the Quantity property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Quantity")]
        public Decimal Quantity
        {
            get { return this.quantityField.GetValueOrDefault() ; }
            set { this.quantityField= value; }
        }



        /// <summary>
        /// Sets the Quantity property
        /// </summary>
        /// <param name="quantity">Quantity property</param>
        /// <returns>this instance</returns>
        public OfferListing WithQuantity(Decimal quantity)
        {
            this.quantityField = quantity;
            return this;
        }



        /// <summary>
        /// Checks if Quantity property is set
        /// </summary>
        /// <returns>true if Quantity property is set</returns>
        public Boolean IsSetQuantity()
        {
            return  this.quantityField != null;

        }


        /// <summary>
        /// Gets and sets the ISPUStoreAddress property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ISPUStoreAddress")]
        public Address ISPUStoreAddress
        {
            get { return this.ISPUStoreAddressField ; }
            set { this.ISPUStoreAddressField = value; }
        }



        /// <summary>
        /// Sets the ISPUStoreAddress property
        /// </summary>
        /// <param name="ISPUStoreAddress">ISPUStoreAddress property</param>
        /// <returns>this instance</returns>
        public OfferListing WithISPUStoreAddress(Address ISPUStoreAddress)
        {
            this.ISPUStoreAddressField = ISPUStoreAddress;
            return this;
        }



        /// <summary>
        /// Checks if ISPUStoreAddress property is set
        /// </summary>
        /// <returns>true if ISPUStoreAddress property is set</returns>
        public Boolean IsSetISPUStoreAddress()
        {
            return this.ISPUStoreAddressField != null;
        }




        /// <summary>
        /// Gets and sets the ISPUStoreHours property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ISPUStoreHours")]
        public String ISPUStoreHours
        {
            get { return this.ISPUStoreHoursField ; }
            set { this.ISPUStoreHoursField= value; }
        }



        /// <summary>
        /// Sets the ISPUStoreHours property
        /// </summary>
        /// <param name="ISPUStoreHours">ISPUStoreHours property</param>
        /// <returns>this instance</returns>
        public OfferListing WithISPUStoreHours(String ISPUStoreHours)
        {
            this.ISPUStoreHoursField = ISPUStoreHours;
            return this;
        }



        /// <summary>
        /// Checks if ISPUStoreHours property is set
        /// </summary>
        /// <returns>true if ISPUStoreHours property is set</returns>
        public Boolean IsSetISPUStoreHours()
        {
            return  this.ISPUStoreHoursField != null;

        }


        /// <summary>
        /// Gets and sets the IsEligibleForSuperSaverShipping property.
        /// </summary>
        [XmlElementAttribute(ElementName = "IsEligibleForSuperSaverShipping")]
        public Boolean IsEligibleForSuperSaverShipping
        {
            get { return this.isEligibleForSuperSaverShippingField.GetValueOrDefault() ; }
            set { this.isEligibleForSuperSaverShippingField= value; }
        }



        /// <summary>
        /// Sets the IsEligibleForSuperSaverShipping property
        /// </summary>
        /// <param name="isEligibleForSuperSaverShipping">IsEligibleForSuperSaverShipping property</param>
        /// <returns>this instance</returns>
        public OfferListing WithIsEligibleForSuperSaverShipping(Boolean isEligibleForSuperSaverShipping)
        {
            this.isEligibleForSuperSaverShippingField = isEligibleForSuperSaverShipping;
            return this;
        }



        /// <summary>
        /// Checks if IsEligibleForSuperSaverShipping property is set
        /// </summary>
        /// <returns>true if IsEligibleForSuperSaverShipping property is set</returns>
        public Boolean IsSetIsEligibleForSuperSaverShipping()
        {
            return  this.isEligibleForSuperSaverShippingField != null;

        }


        /// <summary>
        /// Gets and sets the SalesRestriction property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SalesRestriction")]
        public String SalesRestriction
        {
            get { return this.salesRestrictionField ; }
            set { this.salesRestrictionField= value; }
        }



        /// <summary>
        /// Sets the SalesRestriction property
        /// </summary>
        /// <param name="salesRestriction">SalesRestriction property</param>
        /// <returns>this instance</returns>
        public OfferListing WithSalesRestriction(String salesRestriction)
        {
            this.salesRestrictionField = salesRestriction;
            return this;
        }



        /// <summary>
        /// Checks if SalesRestriction property is set
        /// </summary>
        /// <returns>true if SalesRestriction property is set</returns>
        public Boolean IsSetSalesRestriction()
        {
            return  this.salesRestrictionField != null;

        }


        /// <summary>
        /// Gets and sets the ShippingCharge property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ShippingCharge")]
        public List<ShippingCharge> ShippingCharge
        {
            get
            {
                if (this.shippingChargeField == null)
                {
                    this.shippingChargeField = new List<ShippingCharge>();
                }
                return this.shippingChargeField;
            }
            set { this.shippingChargeField =  value; }
        }



        /// <summary>
        /// Sets the ShippingCharge property
        /// </summary>
        /// <param name="list">ShippingCharge property</param>
        /// <returns>this instance</returns>
        public OfferListing WithShippingCharge(params ShippingCharge[] list)
        {
            foreach (ShippingCharge item in list)
            {
                ShippingCharge.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks if ShippingCharge property is set
        /// </summary>
        /// <returns>true if ShippingCharge property is set</returns>
        public Boolean IsSetShippingCharge()
        {
            return (ShippingCharge.Count > 0);
        }




        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetOfferListingId()) {
                xml.Append("<OfferListingId>");
                xml.Append(EscapeXML(this.OfferListingId));
                xml.Append("</OfferListingId>");
            }
            if (IsSetExchangeId()) {
                xml.Append("<ExchangeId>");
                xml.Append(EscapeXML(this.ExchangeId));
                xml.Append("</ExchangeId>");
            }
            if (IsSetPrice()) {
                Price  price = this.Price;
                xml.Append("<Price>");
                xml.Append(price.ToXMLFragment());
                xml.Append("</Price>");
            } 
            if (IsSetSalePrice()) {
                Price  salePrice = this.SalePrice;
                xml.Append("<SalePrice>");
                xml.Append(salePrice.ToXMLFragment());
                xml.Append("</SalePrice>");
            } 
            if (IsSetAmountSaved()) {
                Price  amountSaved = this.AmountSaved;
                xml.Append("<AmountSaved>");
                xml.Append(amountSaved.ToXMLFragment());
                xml.Append("</AmountSaved>");
            } 
            if (IsSetPercentageSaved()) {
                xml.Append("<PercentageSaved>");
                xml.Append(this.PercentageSaved);
                xml.Append("</PercentageSaved>");
            }
            if (IsSetAvailability()) {
                xml.Append("<Availability>");
                xml.Append(EscapeXML(this.Availability));
                xml.Append("</Availability>");
            }
            if (IsSetAvailabilityAttributes()) {
                AvailabilityAttributes  availabilityAttributes = this.AvailabilityAttributes;
                xml.Append("<AvailabilityAttributes>");
                xml.Append(availabilityAttributes.ToXMLFragment());
                xml.Append("</AvailabilityAttributes>");
            } 
            if (IsSetQuantity()) {
                xml.Append("<Quantity>");
                xml.Append(this.Quantity);
                xml.Append("</Quantity>");
            }
            if (IsSetISPUStoreAddress()) {
                Address  ISPUStoreAddress = this.ISPUStoreAddress;
                xml.Append("<ISPUStoreAddress>");
                xml.Append(ISPUStoreAddress.ToXMLFragment());
                xml.Append("</ISPUStoreAddress>");
            } 
            if (IsSetISPUStoreHours()) {
                xml.Append("<ISPUStoreHours>");
                xml.Append(EscapeXML(this.ISPUStoreHours));
                xml.Append("</ISPUStoreHours>");
            }
            if (IsSetIsEligibleForSuperSaverShipping()) {
                xml.Append("<IsEligibleForSuperSaverShipping>");
                xml.Append(this.IsEligibleForSuperSaverShipping);
                xml.Append("</IsEligibleForSuperSaverShipping>");
            }
            if (IsSetSalesRestriction()) {
                xml.Append("<SalesRestriction>");
                xml.Append(EscapeXML(this.SalesRestriction));
                xml.Append("</SalesRestriction>");
            }
            List<ShippingCharge> shippingChargeList = this.ShippingCharge;
            foreach (ShippingCharge shippingCharge in shippingChargeList) {
                xml.Append("<ShippingCharge>");
                xml.Append(shippingCharge.ToXMLFragment());
                xml.Append("</ShippingCharge>");
            }
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}